package com.itheima.stream流.实例;

import java.util.*;
import java.util.stream.Stream;

public class Demo2 {
    public static void main(String[] args) {
        //streamset();
        //arrayliststream();
        //streamHashMap();
        //arrayStream();
        //ofStream();

    }

    public static void ofStream() {
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
        integerStream.filter(s->s>8).skip(2).limit(4).forEach(s-> System.out.println(s));
    }

    public static void arrayStream() {
        String[] strs={"aaa","bbb","ccc","aaa","ccc","ddd","eee"};
        Arrays.stream(strs).limit(6).distinct().skip(1).forEach(s-> System.out.println(s));
    }

    public static void streamHashMap() {
        HashMap<String,String> map=new HashMap<>();
        map.put("张三","23");
        map.put("李四","24");
        map.put("王五","22");
        map.put("麻六","21");
        map.put("苏七","25");
        long count = map.keySet().stream().count();
        System.out.println(count);
        System.out.println("=================");
        map.keySet().stream().distinct().limit(4).skip(1).forEach(System.out::println);
    }

    public static void arrayliststream() {
        ArrayList<String> list=new ArrayList<>();
        Collections.addAll(list,"张三丰","张无忌","张翠山","张三","王二麻子");
        list.stream().filter(s->s.startsWith("张")).filter(s -> s.length()==3).forEach(System.out::println);
    }

    public static void streamset() {
        HashSet<String> list=new HashSet<>();
        Collections.addAll(list,"张三丰","张无忌","张翠山","张三","王二麻子");
        Collections.addAll(list,"aaa","bbb","ccc","ccc");
        list.stream().limit(3).skip(1).distinct().forEach(System.out::println);
    }
}
